﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Entities</title>
<link type="text/css" rel="stylesheet" href="../bootstrap.min.css" />
</head>

<body>

<div class="bs-callout bs-callout-warning">
	<h4>About Multi Tenancy</h4>
	<p>It's strongly suggested to read <a href="/Pages/Documents/Multi-Tenancy">
	multi tenancy documentation</a> before this document.</p>
</div>

<div class="document-contents">

<h3>Enabling Multi Tenancy</h3>
<p>ASP.NET Boilerplate and module-zero can run <strong>multi-tenant</strong> or
<strong>single-tenant</strong> modes. Multi-tenancy is disabled by default. We 
can enable it in PreInitialize method of our
<a href="/Pages/Documents/Module-System">module</a> as shown below:</p>
<pre lang="cs">[DependsOn(typeof(AbpZeroCoreModule))]
public class MyCoreModule : AbpModule
{
    public override void PreInitialize()
    {
        <strong>Configuration.MultiTenancy.IsEnabled = true;
</strong>    }

    ...
}</pre>
<p>Note that: Even our application is not multi-tenant, we must define a default 
tenant (see Default Tenant section of this document).&nbsp;</p>
<p>When we create a project <a href="/Templates">template</a> based on ASP.NET 
Boilerplate and module-zero, we have a <strong>Tenant</strong> entity and
<strong>TenantManager</strong> domain service.</p>
<h3>Tenant Entity</h3>
<p>Tenant entity represents a Tenant of the application.</p>
<pre lang="cs">public class Tenant : AbpTenant&lt;Tenant, User&gt;
{

}</pre>
<p>It's derived from generic <strong>AbpTenant</strong> class. Tenant entities 
are stored in <strong>AbpTenants</strong> table in the database. You can add 
your custom properties to Tenant class.</p>
<p>AbpTenant class defines some base properties, most importants are:</p>
<ul>
	<li><strong>TenancyName</strong>: This is <strong>unique</strong> name of a 
	tenant in the application. It should not be changed normally. It can be used 
	to allocate subdomains to tenants like '<strong>mytenant</strong>.mydomain.com'. 
	Tenant.<strong>TenancyNameRegex</strong> constant defines the naming rule.</li>
	<li><strong>Name</strong>: An arbitrary, human-readable, long name of the 
	tenant.</li>
	<li><strong>IsActive</strong>: True, if this tenant can use the application. 
	If it's false, no user of this tenant can login to to system.</li>
</ul>
<p>AbpTenant class is inherited from <strong>FullAuditedEntity</strong>. That 
means it has creation, modification and deletion <strong>audit properties</strong>. 
It's also <strong><a href="/Pages/Documents/Data-Filters#DocSoftDelete">
Soft-Delete</a></strong>. So, when we delete a tenant, it's not deleted from 
database, just marked as deleted.</p>
<p>Finally, <strong>Id</strong> of AbpTenant is defined as <strong>int</strong>.</p>
<h3>Tenant Manager</h3>
<p>Tenant Manager is a service to perform <strong>domain logic </strong>for 
tenants:</p>
<pre lang="cs">public class TenantManager : AbpTenantManager&lt;Tenant, Role, User&gt;
{
    public TenantManager(IRepository&lt;Tenant&gt; tenantRepository)
        : base(tenantRepository)
    {

    }
}</pre>
<p>TenantManager is also used to manage tenant
<a href="/Pages/Documents/Feature-Management">features</a>. You can add your own methods here. Also you can override any method of 
AbpTenantManager base class for your own needs.</p>
<h3>Default Tenant</h3>
<p>ASP.NET Boilerplate and module-zero assumes that there is a pre-defined tenant 
which's TenancyName is '<strong>Default</strong>' and Id is <strong>1</strong>. 
In a single-tenant application, this is used as as the single tenant. In a 
multi-tenant application, you can delete it or make it passive.</p>

</div>

</body>

</html>
